package il.ac.bgu.soa2009.hw5.restuarnt;

import il.ac.bgu.soa2009.hw5.schema.WeekDay;

import java.util.Date;
import java.util.GregorianCalendar;

/**
 * User: Henry
 * Date: 23/02/2009
 * Time: 14:38:20
 */
public class DateUtils {

    public static WeekDay getDayOfWeek(Date day) {
        WeekDay res;
        GregorianCalendar gregorianCalendar = new GregorianCalendar();
        gregorianCalendar.setTime(day);
        switch (gregorianCalendar.get(GregorianCalendar.DAY_OF_WEEK)) {
            case GregorianCalendar.SUNDAY:
                res = WeekDay.Sunday;
                break;
            case GregorianCalendar.MONDAY:
                res = WeekDay.Monday;
                break;
            case GregorianCalendar.TUESDAY:
                res = WeekDay.Tuesday;
                break;
            case GregorianCalendar.WEDNESDAY:
                res = WeekDay.Wednesday;
                break;
            case GregorianCalendar.THURSDAY:
                res = WeekDay.Thursday;
                break;
            case GregorianCalendar.FRIDAY:
                res = WeekDay.Friday;
                break;
            case GregorianCalendar.SATURDAY:
                res = WeekDay.Saturday;
                break;
            default:
                throw new IllegalArgumentException("Unknown date!");
        }
        return res;
    }
}
